

using System;
using System.Diagnostics;
using CStock;



namespace EForms
{
	/// <summary>
	/// Summary description for TreeNodeInfo.
	/// </summary>
	public class TreeNodeInfo : Object , ITreeNodeInfo
	{
		#region fields and Constants

		private bool DEBUG = false;
		public const string PORTFOLIO = "Portfolio";
		public const string SHARE = "Share";
		public const string PARAMETER = "Parameter";
		private string baseType;
		private string dataClassItemName;
		private string portfolioName;
		private object portfolioOrDataItem;

		#endregion

		#region Constructor
		
		private void initTreeNodeInfo()
		{
			this.BaseType="";
			this.DataItemName = "";
			this.PortfolioName="";
		}
		private void initTreeNodeInfo(string newNodeInfo)
		{
			try
			{	

				newNodeInfo=newNodeInfo.Trim();
				string[] tokens=newNodeInfo.Split(new char[]{'.'},3);
				if (tokens.Length>3){throw new Exception("Error due to Number of Tokens of TreeNodeInfoString!");}
				switch (tokens.Length)
				{
					case 1:
					{
						this.BaseType=tokens[0];
						break;
					}
					case 2:
					{
						this.PortfolioName=tokens[0];
						this.BaseType=tokens[1];
						break;
					}
					case 3:
					{
						this.PortfolioName=tokens[0];
						this.DataItemName = tokens[1];
						this.BaseType = tokens[2];
						break;
					}
					default:
					{
						throw new Exception("Error due to Number of Tokens of TreeNodeInfoString!");
					}
				}
				TreeNodeInfoToscreen(newNodeInfo);	
			}
			catch (Exception exc)
			{
				Debug.Assert
					(false,"TreeNodeInfo-TreeNodeInfo(): "+"Error creating TreeNodeInfo["+newNodeInfo+"]"+exc.Message);
			}
		}
		private void initTreeNodeInfo(object newNodeData)
		{
			 this.portfolioOrDataItem = newNodeData;
		}
		public TreeNodeInfo()
		{
			initTreeNodeInfo();
		}
		public TreeNodeInfo(string newNodeInfo):this()
		{
			initTreeNodeInfo(newNodeInfo);
		}
		public TreeNodeInfo(string newNodeInfo, object newNodeData) : this(newNodeInfo)
		{
			initTreeNodeInfo(newNodeData);
		}
		#endregion

		#region Properties
		
	
		public string BaseType
		{
			get
			{
				return this.baseType;
			}
			set
			{
				this.baseType=value;
			}
		}
	
		public string DataItemName
		{
			get
			{
				return this.dataClassItemName;
			}
			set
			{
				this.dataClassItemName = value;
			}
		}
		
		public string PortfolioName
		{
			get
			{
				return this.portfolioName;
			}
			set
			{
				this.portfolioName=value;
			}
		}
		
		public object PortfolioOrDataItem
		{
			get
			{
				return this.portfolioOrDataItem;
			}
			set
			{
				this.portfolioOrDataItem = value;
			}
		}
		#endregion

		#region implementations

		public override string ToString()
		{
			return "["+"Type="+this.BaseType+"Share="+this.DataItemName+"Portfolio="+this.PortfolioName+"]";
		}
		
		private void TreeNodeInfoToscreen(string treeNodeInfo)
		{
			if (this.DEBUG)
			{
				System.Diagnostics.Debug.WriteLine
				(
					"TreeNodeInfo-TreeNodeInfo(): "+"["+treeNodeInfo+"]"+"->"+this.ToString()
				);
			}
		}
		#endregion
	}
}
